<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<button>+</button>

<body>
  <script>
    /*
    普通函数的调用方式决定了this的值(谁调用函数this就指向谁)
    普通函数没有明确调用者时this指向window，严格模式下this指向undefined 
     */
    console.log(this) //window

    function getThis() {
      console.log(this) //window
    }
    getThis()

    setTimeout(() => {
      console.log(this) //window
    }, 1000)


    document.querySelector("button").addEventListener("click", function () {
      console.log(this); //button
    })

    const person = {
      name:"陶品奇",
      age:22,
      writeCode() {
        console.log(this) //person
      }
    }
    person.writeCode()
  </script>
</body>

</html>